package com.wechat.order.dataobject.mapper;

import com.wechat.order.dataobject.ProductCategory;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * Created by zzy on 2017/12/24.
 */
@Mapper
public interface ProductCategoryMapper {

    @Insert("insert into tb_product_category(category_name,category_type) values (#{category_name,jdbcType=VARCHAR},#{category_type,jdbcType=INTEGER})")
    int insertByMap(Map<String,Object> map);

    @Insert("insert into tb_product_category(category_name,category_type) values (#{categoryName,jdbcType=VARCHAR},#{categoryType,jdbcType=INTEGER})")
    int insertByObject(ProductCategory productCategory);

    @Select("select * from tb_product_category where category_type=#{categoryType}")
    @Results({
            @Result(column = "category_type",property = "categoryType"),
            @Result(column = "category_id",property = "categoryId"),
            @Result(column = "category_name",property = "categoryName"),
    })
   ProductCategory findByCategoryType(Integer categoryType);


    @Select("select * from tb_product_category where category_name=#{categoryName}")
    @Results({
            @Result(column = "category_type",property = "categoryType"),
            @Result(column = "category_id",property = "categoryId"),
            @Result(column = "category_name",property = "categoryName"),
    })
    List<ProductCategory> findByCategoryName(String categoryName);


    @Update("update tb_product_category set category_name=#{categoryName} where category_type=#{categoryType}")
    int updateByCategoryType(@Param("categoryType") Integer categoryType,@Param("categoryName") String categoryName);


    @Delete("delete from tb_product_category where category_type=#{categoryType}")
    int deleteByCategoryType(Integer categoryType);

    ProductCategory selectByCategory(Integer categoryType);


    int updateDescStock(@Param("productId") String productId,@Param("num") Integer num);
}
